package http_utils.utils;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Build;

import http_utils.interfaces.IHttpPostListener;

import java.util.Map;

import http_utils.asynctask.HttpPostAsyncTask;

import utils.IToast;

/**
 * Created by admin on 2017/3/20.
 */

public class Ipost {

    public static void send(Activity activity, String url, Map<String, Object> postParams, IHttpPostListener postListener, boolean showLoading) {
        if (!NetState.isNetworkAvailable(activity)) {
            IToast.show(activity, "网络未连接!!");
            return;
        }
        if (showLoading) {
            LoadingUtils.progressDialogShow(activity);
        }

        HttpPostAsyncTask postAsyncTask = new HttpPostAsyncTask(url, postParams,
                postListener);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            postAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        } else {
            postAsyncTask.execute();
        }
    }

    public static boolean isTimeOut(Activity activity, String result) {
        if (null != result) {
            if (result.equals("timeout")) {
                IToast.show(activity, "网络超时");
                return true;
            }
        }
        return false;
    }

}
